import type { NvFormOption, NvFormProps } from './types'
import { computed } from 'vue'

export function useOption(props: NvFormProps) {
  return computed<NvFormOption>(() => {
    const { mode, option } = props
    if (mode !== 'view')
      return option

    return {
      showLabel: option.showLabel,
      labelWidth: option.labelWidth,
      labelAlign: option.labelAlign,
      labelPlacement: option.labelPlacement,
      size: option.size,
      showRequireMark: false,
      showFeedback: false,
      formActions: false,
      fields: Object.fromEntries(
        Object.entries(option.fields).map(([field, op]) => {
          return [field, {
            type: op.type,
            label: op.label,
            showLabel: op.showLabel,
            labelWidth: op.labelWidth,
            labelStyle: op.labelStyle,
            labelAlign: op.labelAlign,
            labelPlacement: op.labelPlacement,
            span: op.span,
            verticalSpan: op.verticalSpan,
            offset: op.offset,
            first: option.first,
            suffix: op.suffix,
            formOrder: op.formOrder,
            formVisible: op.formVisible,
            dict: op.dict,
            props: op.props,
            slots: op.slots,
          }]
        }),
      ),
      group: option.group,
    }
  })
}
